import type { AddRoleParams, DeleteRoleParams, GetRoleListParams, GetUserRoleListParams } from '@/model/UserRoleBo';
import * as UserApi from '@/api/UserRoleApi';

export class UserRoleService {
  /**
   * 获取用户已分配角色列表
   * @param data
   * @returns AssignRoleResponse
   */
  public static async getUserAssignRoleList(data: GetUserRoleListParams) {
    try {
      const response = await UserApi.getUserAssignRole(data);
      return {
        code: response.code,
        data: response.data,
      };
    } catch (err) {
      console.error('接口调用失败:', err);
    }
    return {
      code: '1',
      data: {},
    };
  }

  /**
   * 删除用户已分配角色列表
   * @param data
   * @returns AssignRoleResponse
   */
  public static async deleteUserAssignRole(data: DeleteRoleParams) {
    try {
      const response = await UserApi.deleteUserAssignRole(data);
      return {
        code: response.code,
        message: response.message,
      };
    } catch (err) {
      console.error('接口调用失败:', err);
    }
    return {
      code: '1',
      data: {},
    };
  }

  /**
   * 获取全部角色列表
   * @param data
   * @returns AssignRoleResponse
   */
  public static async getRoleList(data: GetRoleListParams) {
    try {
      const response = await UserApi.getRoleList(data);
      return {
        code: response.code,
        data: response.data,
      };
    } catch (err) {
      console.error('接口调用失败:', err);
    }
    return {
      code: '1',
      data: {},
    };
  }

  /**
   * 获取全部角色列表
   * @param data
   * @returns AssignRoleResponse
   */
  public static async getAssignableRoleList(data: GetRoleListParams) {
    try {
      const response = await UserApi.getAssignableRoleList(data);
      return {
        code: response.code,
        data: response.data,
      };
    } catch (err) {
      console.error('接口调用失败:', err);
    }
    return {
      code: '1',
      data: {},
    };
  }

  /**
   * 删除用户已分配角色列表
   * @param data
   * @returns AssignRoleResponse
   */
  public static async addUserAssignRole(data: AddRoleParams) {
    try {
      const response = await UserApi.addUserAssignRole(data);
      return {
        code: response.code,
        message: response.message,
      };
    } catch (err) {
      console.error('接口调用失败:', err);
    }
    return {
      code: '1',
      data: {},
    };
  }
}
